<?php
require 'Model.php';
class CartypeModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getCartypeList(){
			$sql = 'select * from cartype';
			$data = $this->conn->query($sql);
			//var_dump($sql);
			//$this->conn = new ConnDB();
			return $data;
		}


		function getCartypeByID($id){
			$sql = "select * from cartype where tid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatecartype($data){
			/*if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}*/
		  	$cartype = array(
				'tid' =>$_POST['tid'],
				'cartypename' => $_POST['cartypename'],
				);
		  	//var_dump($carbrand);
		  	$sql='update cartype set cartypename="'.$cartype['cartypename'].'" where tid="'.$cartype['tid'].'"';
			$result = $this->conn->query($sql);
			return $result;
		}

		function addCartype($data){
			//var_dump($data);
			//如果选择了照片，则上传照片文件
			/*if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}*/
			$cartype = array(
				'tid' =>'',
				'cartypename' => $data['cartypename'],
				//'bid' => $data['bid'],
				);
			$keys = implode(',',array_keys($cartype));
			$values = implode("','",array_values($cartype));
			/*$sql = "insert into videos values ('$video[uid]','$video[uname]','$video[password]','$video[gender]','$video[birthdate]','$video[hobby]','$video[degree]','$video[intro]','$video[pic]')";*/
			$sql="insert into cartype ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Delcartype($id){
			$sql = "Delete from cartype where tid=".$id;
			//var_dump($sql);
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>